package org.example.power;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

//5.选出400卡路里以下的菜肴,按照卡路里排序,提取菜肴的名称,只选前3个,将所有名称保存在List中
public class SelectKll {
    public static class Kll{
        private String foodName;
        private Double kllNumber;
        public Kll(){}
        public  Kll(String foodName, Double kllNumber){
            this.foodName=foodName;
            this.kllNumber=kllNumber;
        }

        public String getFoodName() {
            return foodName;
        }

        public void setFoodName(String foodName) {
            this.foodName = foodName;
        }

        public Double getKllNumber() {
            return kllNumber;
        }

        public void setKllNumber(Double kllNumber) {
            this.kllNumber = kllNumber;
        }


        @Override
        public String toString() {
            return "Kll{" +
                    "foodName='" + foodName + '\'' +
                    ", kllNumber=" + kllNumber +
                    '}';
        }
    }
    public static void main(String[] args){
        List<Kll> kllList=new ArrayList<>();
        kllList.add(new Kll("鸡肉",200d));
        kllList.add(new Kll("牛肉",800d));
        kllList.add(new Kll("猪肉",230d));
        kllList.add(new Kll("鸭肉",900d));
        kllList.add(new Kll("羊肉",100d));
        kllList.add(new Kll("鹅肉",100d));
        List<String> collect=kllList.stream().filter(kll -> kll.getKllNumber()<400)
                .sorted(Comparator.comparing(Kll::getKllNumber)).
                        map(Kll::getFoodName).limit(3).collect(Collectors.toList());

        System.out.println(collect);

        Optional<Kll> optional = kllList.stream().findAny();
        if (optional.isPresent()){
            Kll dish = optional.get();
            System.out.println(dish);
        }

    }



}
